<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="140px">
      <el-row  :gutter="15">
        <el-col :span="12">
          <!-- （4已招聘(已签订合同) 5已经聘用未签订合同 6已离职(已解除劳动合同)  7无聘用关系） -->
            <el-form-item label="聘用状态" prop="isFit"
                :rules="[
                  {required: true, message:'聘用状态不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.isFit" placeholder="请选择"  style="width: 100%;">
                          <!-- <el-option
                            v-for="item in $dictUtils.getDictList('isFit')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option> -->
                          <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value * 1">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="求职状态" prop="jobSearchingStatus"
                :rules="[
                  {required: true, message:'求职状态不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.jobSearchingStatus" placeholder="请填写求职状态"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="姓名" prop="userName"
                :rules="[
                  {required: true, message:'姓名不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.realName" placeholder="请填写姓名"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="手机号" prop="phone"
                :rules="[
                  {required: true, message:'手机号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.phone" placeholder="请填写手机号"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="电子邮箱" prop="email"
                :rules="[
                  {required: true, message:'电子邮箱不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.email" placeholder="请填写电子邮箱"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="身份证号" prop="idCard"
                :rules="[
                  {required: true, message:'身份证号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.idCard" placeholder="请填写身份证号"></el-input>
           </el-form-item>
        </el-col>
        
        <el-col :span="12">
            <el-form-item label="性别" prop="sex"
                :rules="[
                  {required: true, message:'性别不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.sex" placeholder="请填写性别"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="年龄" prop="age"
                :rules="[
                  {required: true, message:'年龄不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.age" placeholder="请填写年龄"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工作经验年限" prop="workingYears"
                :rules="[
                  {required: true, message:'工作经验年限不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.workingYears" placeholder="请填写工作经验年限"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="毕业院校" prop="graduatedSchool"
                :rules="[
                  {required: true, message:'毕业院校不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.graduatedSchool" placeholder="请填写毕业院校"></el-input>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="参加工作时间" prop="plusJobsTime"
                :rules="[
                  {required: true, message:'参加工作时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.plusJobsTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="现住址" prop="currentAddress"
                :rules="[
                  {required: true, message:'现住址不能为空', trigger:'blur'}
                 ]">
                      <!-- <CityPicker style="width:100%"
                        :value="inputForm.currentAddress"
                        :clearable="true" 
                        :accordion="true"
                        @getValue="(value) => {inputForm.currentAddress=value}"/> -->
                        <el-input v-model="inputForm.currentAddress" placeholder="请填写现住址"></el-input>
           </el-form-item>
        </el-col>
        
        <el-col :span="12">
            <el-form-item label="期望岗位" prop="job"
                :rules="[
                 ]">
              <el-input v-model="inputForm.job" placeholder="请填写岗位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="紧急联系人" prop="emergencyContact"
                :rules="[
                  {required: true, message:'紧急联系人不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.emergencyContact" placeholder="请填写紧急联系人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="紧急联系人手机号" prop="emergencyContactPhone"
                :rules="[
                  {required: true, message:'紧急联系人手机号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.emergencyContactPhone" placeholder="请填写紧急联系人手机号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="户籍所在地" prop="area"
                :rules="[
                  {required: true, message:'户籍所在地不能为空', trigger:'blur'}
                 ]">
                      <!-- <CityPicker 
                         style="width:100%"
                        :value="inputForm.area"
                        :clearable="true" 
                        :accordion="true"
                        @getValue="(value) => {inputForm.area=value}"/> -->
                        <el-input v-model="inputForm.area" placeholder="请填写户籍所在地"></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import CityPicker from '@/components/cityPicker'
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        headPortraitArra: [],
        idCardFrondArra: [],
        idCardBackArra: [],
        individualCertificationArra: [],
        options: [
          { value: 0, label: '复试中' },
          { value: 1, label: '聘用中' },
          { value: 2, label: '入职驳回' },
          { value: 3, label: '入职进行中' },
        ],
        inputForm: {
          id: '',
          employmentStatus: '',
          userName: '',
          passWord: '',
          headPortrait: '',
          phone: '',
          email: '',
          realName: '',
          idCard: '',
          idCardFrond: '',
          idCardBack: '',
          gradeRatings: '',
          isApprove: '',
          attstatus: '',
          loginRoot: '',
          individualCertification: '',
          token: '',
          sex: '',
          age: '',
          workingYears: '',
          graduatedSchool: '',
          plusJobsTime: '',
          currentAddress: '',
          numbering: '',
          isDispatch: '',
          rongyunuserid: '',
          rongyuntoken: '',
          department: {
            id: ''
          },
          branchdepart: {
            id: ''
          },
          job: '',
          openingbank: '',
          banknumber: '',
          bankcard: '',
          workCondition: '',
          emergencyContact: '',
          emergencyContactPhone: '',
          address: '',
          area: '',
          communication: '',
          interview: '',
          collect: '',
          delivery: '',
          terminaId: '',
          householdRegister: '',
          interest: '',
          drivingLicense: '',
          education: '',
          balance: '',
          paymentPassword: '',
          remarks: '',
          telePhone: '',
          individualcertificationvideo: '',
          ismerchantauthentication: ''
        }
      }
    },
    components: {
      CityPicker,
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建报名信息`
        } else if (method === 'edit') {
          this.title = `修改报名信息`
        } else if (method === 'view') {
          this.title = `报名信息`
        }
        this.headPortraitArra = []
        this.idCardFrondArra = []
        this.idCardBackArra = []
        this.individualCertificationArra = []
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/userinformation/userInformation/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.userInformation)
              this.inputForm.isFit = data.userInformation.isFit ? data.userInformation.isFit : ''
              if(this.inputForm.isFit){
                this.inputForm.isFit = data.userInformation.isFit * 1
              }
              this.inputForm.jobSearchingStatus = data.userInformation.jobSearchingStatus
              this.inputForm.jobSearchingStatus == '0' ? this.inputForm.jobSearchingStatus = '离职-随时到岗' : this.inputForm.jobSearchingStatus == '1' ? this.inputForm.jobSearchingStatus = '在职-考虑机会' : this.inputForm.jobSearchingStatus == '2' ? this.inputForm.jobSearchingStatus = '在职-暂不考虑' : '无聘用关系'
              this.inputForm.headPortrait.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.headPortraitArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.inputForm.idCardFrond.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.idCardFrondArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.inputForm.idCardBack.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.idCardBackArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.inputForm.individualCertification.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.individualCertificationArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/userinformation/userInformation/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>